package com.voltmao.webpro.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 日期处理工具类
 * Created by HuangPeng .
 * Created on 2017-03-30 16:38
 * Strive not to waste time every day, Come on!
 */
public class DateProcessingUtil {

    /**
     * Description: 根据日期得到周几
     *
     * @Author: HuangPeng.
     * @param: Date
     * @return: String
     * @Date: 2017/3/30 16:44
     */
    public String getDayOfTheWeek(Date date, String name) {
        String[] weekDaysName = {name + "日", name + "一", name + "二", name + "三", name + "四", name + "五", name + "六"};
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int intWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return weekDaysName[intWeek];
    }

    /**
     * Description:根据两段日期得到之间的日值
     *
     * @Author: HuangPeng.
     * @Date: 2017/3/30 16:51
     */
    public List<Date> dateBetweenDates(Date date1, Date date2) {
        List<Date> result = new ArrayList<Date>();
        Calendar tempStart = Calendar.getInstance();
        tempStart.setTime(date1);
        tempStart.add(Calendar.DAY_OF_YEAR, 1);

        Calendar tempEnd = Calendar.getInstance();
        tempEnd.setTime(date2);
        while (tempStart.before(tempEnd)) {
            result.add(tempStart.getTime());
            tempStart.add(Calendar.DAY_OF_YEAR, 1);
        }
        result.add(0, date1);
        result.add(date2);
        return result;
    }


    /**
     * Description: 获取未来第几天的日期
     *
     * @Author: HuangPeng.
     * @Date: 2017/4/24 17:32
     */
    public static Date getFetureDate(int past) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
        Date today = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String result = format.format(today);
        //Log.e(null, result);
        return today;
    }
}
